package com.flurry.sdk;

import android.net.Uri;
import android.text.TextUtils;
import android.webkit.MimeTypeMap;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.regex.Pattern;

public final class mc {
    private static final Pattern a = Pattern.compile("/");

    /* JADX WARNING: Code restructure failed: missing block: B:9:0x0035, code lost:
        r2 = r4.indexOf(r0);
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public static String a(String r4) {
        /*
            boolean r0 = android.text.TextUtils.isEmpty(r4)
            if (r0 == 0) goto L_0x0007
        L_0x0006:
            return r4
        L_0x0007:
            java.net.URI r0 = i(r4)
            if (r0 == 0) goto L_0x0006
            java.lang.String r0 = r0.getScheme()
            boolean r1 = android.text.TextUtils.isEmpty(r0)
            if (r1 == 0) goto L_0x0027
            java.lang.StringBuilder r0 = new java.lang.StringBuilder
            java.lang.String r1 = "http"
            r0.<init>(r1)
            java.lang.StringBuilder r0 = r0.append(r4)
            java.lang.String r4 = r0.toString()
            goto L_0x0006
        L_0x0027:
            java.util.Locale r1 = java.util.Locale.getDefault()
            java.lang.String r1 = r0.toLowerCase(r1)
            boolean r2 = r0.equals(r1)
            if (r2 != 0) goto L_0x0006
            int r2 = r4.indexOf(r0)
            if (r2 < 0) goto L_0x0006
            java.lang.StringBuilder r3 = new java.lang.StringBuilder
            r3.<init>()
            java.lang.StringBuilder r1 = r3.append(r1)
            int r0 = r0.length()
            int r0 = r0 + r2
            java.lang.String r0 = r4.substring(r0)
            java.lang.StringBuilder r0 = r1.append(r0)
            java.lang.String r4 = r0.toString()
            goto L_0x0006
        */
        throw new UnsupportedOperationException("Method not decompiled: com.flurry.sdk.mc.a(java.lang.String):java.lang.String");
    }

    public static String b(String str) {
        URI i;
        URI a2;
        if (TextUtils.isEmpty(str) || (i = i(str)) == null) {
            return str;
        }
        URI normalize = i.normalize();
        if (normalize.isOpaque() || (a2 = a(normalize.getScheme(), normalize.getAuthority(), "/", (String) null, (String) null)) == null) {
            return str;
        }
        return a2.toString();
    }

    public static String c(String str) {
        URI i;
        URI resolve;
        if (TextUtils.isEmpty(str) || (i = i(str)) == null) {
            return str;
        }
        URI normalize = i.normalize();
        if (normalize.isOpaque() || (resolve = normalize.resolve("./")) == null) {
            return str;
        }
        return resolve.toString();
    }

    public static String a(String str, String str2) {
        URI i;
        String str3;
        String str4;
        if (TextUtils.isEmpty(str) || TextUtils.isEmpty(str2) || (i = i(str)) == null) {
            return str;
        }
        URI normalize = i.normalize();
        URI i2 = i(str2);
        if (i2 == null) {
            return str;
        }
        URI normalize2 = i2.normalize();
        if (normalize.isOpaque() || normalize2.isOpaque()) {
            return str;
        }
        String scheme = normalize.getScheme();
        String scheme2 = normalize2.getScheme();
        if (scheme2 == null && scheme != null) {
            return str;
        }
        if (scheme2 != null && !scheme2.equals(scheme)) {
            return str;
        }
        String authority = normalize.getAuthority();
        String authority2 = normalize2.getAuthority();
        if (authority2 == null && authority != null) {
            return str;
        }
        if (authority2 != null && !authority2.equals(authority)) {
            return str;
        }
        String path = normalize.getPath();
        String path2 = normalize2.getPath();
        String[] split = a.split(path, -1);
        String[] split2 = a.split(path2, -1);
        int length = split.length;
        int length2 = split2.length;
        int i3 = 0;
        while (i3 < length2 && i3 < length && split[i3].equals(split2[i3])) {
            i3++;
        }
        String query = normalize.getQuery();
        String fragment = normalize.getFragment();
        StringBuilder sb = new StringBuilder();
        if (i3 == length2 && i3 == length) {
            String query2 = normalize2.getQuery();
            String fragment2 = normalize2.getFragment();
            boolean equals = TextUtils.equals(query, query2);
            boolean equals2 = TextUtils.equals(fragment, fragment2);
            if (!equals || !equals2) {
                if (!equals || TextUtils.isEmpty(fragment)) {
                    str3 = query;
                } else {
                    str3 = null;
                }
                if (!TextUtils.isEmpty(str3) || !TextUtils.isEmpty(fragment)) {
                    query = str3;
                    str4 = fragment;
                } else {
                    sb.append(split[length - 1]);
                    str4 = fragment;
                }
                fragment = str4;
            } else {
                fragment = null;
                query = null;
            }
        } else {
            int i4 = length - 1;
            int i5 = length2 - 1;
            for (int i6 = i3; i6 < i5; i6++) {
                sb.append("..");
                sb.append("/");
            }
            while (i3 < i4) {
                sb.append(split[i3]);
                sb.append("/");
                i3++;
            }
            if (i3 < length) {
                sb.append(split[i3]);
            }
            if (sb.length() == 0) {
                sb.append(".");
                sb.append("/");
            }
        }
        URI a2 = a((String) null, (String) null, sb.toString(), query, fragment);
        if (a2 != null) {
            return a2.toString();
        }
        return str;
    }

    private static URI i(String str) {
        try {
            return new URI(str);
        } catch (URISyntaxException e) {
            return null;
        }
    }

    private static URI a(String str, String str2, String str3, String str4, String str5) {
        try {
            return new URI(str, str2, str3, str4, str5);
        } catch (URISyntaxException e) {
            return null;
        }
    }

    public static boolean d(String str) {
        if (TextUtils.isEmpty(str)) {
            return false;
        }
        Uri parse = Uri.parse(str);
        if (parse.getScheme() == null || !parse.getScheme().equals("market")) {
            return false;
        }
        return true;
    }

    public static boolean e(String str) {
        if (TextUtils.isEmpty(str)) {
            return false;
        }
        Uri parse = Uri.parse(str);
        if (parse.getScheme() == null) {
            return false;
        }
        if (parse.getScheme().equals("http") || parse.getScheme().equals("https")) {
            return true;
        }
        return false;
    }

    public static boolean f(String str) {
        if (TextUtils.isEmpty(str)) {
            return false;
        }
        Uri parse = Uri.parse(str);
        if (parse.getHost() == null || !parse.getHost().equals("play.google.com") || parse.getScheme() == null || !parse.getScheme().startsWith("http")) {
            return false;
        }
        return true;
    }

    public static boolean g(String str) {
        String mimeTypeFromExtension;
        if (TextUtils.isEmpty(str) || (mimeTypeFromExtension = MimeTypeMap.getSingleton().getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(str))) == null || !mimeTypeFromExtension.startsWith("video/")) {
            return false;
        }
        return true;
    }

    public static boolean h(String str) {
        URI i;
        if (TextUtils.isEmpty(str) || (i = i(str)) == null) {
            return false;
        }
        if (i.getScheme() == null || "http".equalsIgnoreCase(i.getScheme()) || "https".equalsIgnoreCase(i.getScheme())) {
            return true;
        }
        return false;
    }

    public static String b(String str, String str2) {
        if (TextUtils.isEmpty(str)) {
            return str;
        }
        try {
            if (new URI(str).isAbsolute() || TextUtils.isEmpty(str2)) {
                return str;
            }
            URI uri = new URI(str2);
            return uri.getScheme() + "://" + uri.getHost() + str;
        } catch (Exception e) {
            return str;
        }
    }
}
